package com.mp3s.interface3;

import cn.hutool.core.date.DateTime;

public class TradeTime {

    public static boolean isTradeTime(){

        // return true;

        // 获得当前日期
        int hourStart = 9;
        int hourEnd = 15;
        int MinStart = 30;
        int MinEnd = 0;
        DateTime dt = DateTime.now();
        
        //非工作日
        int fd = dt.dayOfWeek();
        if(fd == 1 || fd == 7){
            return false;
        }


        int n1  = dt.hour(true);
        int n2  = dt.minute();
        if(n1 < hourStart || n1 > hourEnd){
            return false;
        }
        if(n1 == hourStart && n2 < MinStart){
            return false;
        }

        if(n1 == hourEnd && n2 > MinEnd){
            return false;
        }

        return true;
    }

    
    public static boolean isBTime(){
        // 14:25以后触发Buy
        int hourEnd = 14;
        int MinStart = 25;
        DateTime dt = DateTime.now();
        //非工作日
        int fd = dt.dayOfWeek();
        if(fd == 1 || fd == 7){
            return false;
        }
        //时间范围
        int n1  = dt.hour(true);
        int n2  = dt.minute();
        if(n1 != hourEnd){
            return false;
        }
        if( n2 < MinStart){
            return false;
        }
        return true;
    }


    public static boolean isStrategyTime(){

        // return true;

        // 获得当前日期
        int hourStart = 8;
        int hourEnd = 18;
        int MinStart = 30;
        int MinEnd = 0;
        DateTime dt = DateTime.now();
        
        //非工作日
        int fd = dt.dayOfWeek();
        if(fd == 1 || fd == 7){
            return false;
        }

        int n1  = dt.hour(true);
        int n2  = dt.minute();
        if(n1 < hourStart || n1 > hourEnd){
            return false;
        }
        if(n1 == hourStart && n2 < MinStart){
            return false;
        }

        if(n1 == hourEnd && n2 > MinEnd){
            return false;
        }

        return true;
    }

    //backtest time
    public static boolean isBTTime(){
        // 15:00以后触发backtest
        int hourStart = 15;
        int hourEnd = 16;
        DateTime dt = DateTime.now();
        //非工作日
        int fd = dt.dayOfWeek();
        if(fd == 1 || fd == 7){
            return false;
        }
        //时间范围
        int n1  = dt.hour(true);
        int n2  = dt.minute();
        if(n1 < hourStart){
            return false;
        }
        if( n1 >= hourEnd){
            return false;
        }
        return true;
    }
}
